GetShootingsBySchoolQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 22
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 19 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetShootingsBySchoolQuery } from './GetShootingsBySchoolQuery';
4
import { IShootingRepository } from 'src/Domain/School/Repository/IShootingRepository';
5
import { ShootingSummaryView } from '../../View/ShootingSummaryView';
6
7
@QueryHandler(GetShootingsBySchoolQuery)
8
export class GetShootingsBySchoolQueryHandler {
9
  constructor(
10
    @Inject('IShootingRepository')
11
    private readonly shootingRepository: IShootingRepository
12
  ) {}
13
14
  public async execute({ schoolId }: GetShootingsBySchoolQuery): Promise<ShootingSummaryView[]> {
15
    const shootingViews: ShootingSummaryView[] = [];
16
    const shootings = await this.shootingRepository.findBySchool(
17
      schoolId
18
    );
19
20
    for (const shooting of shootings) {
21
      shootingViews.push(
22
        new ShootingSummaryView(
23
          shooting.getId(),
24
          shooting.getName(),
25
          shooting.getStatus(),
26
          shooting.getShootingDate()
27
        )
28
      );
29
    }
30
31
    return shootingViews;
32
  }
33
}
34